#include "createWindow.h"

using namespace codex;

const codex::EventType EvtData_Destroy_Actor::sk_EventType("destroy_actor");

tBOOL OnMemoryWarning::HandleEvent(codex::IEventData const & e)
{
	cdxTrace( ((tString)e.GetEventType().getStr() + " - ").c_str() );
	return TRUE;
}

//typedef shared_pinter<>

tBOOL createWindow::listener(codex::IEventData const& e){
	
	return true;
}

//tBOOL(Object::*ptr)(codex::IEventData const& event) = &Object::Touch;
//codex::Listener e = reinterpret_cast<codex::Listener>(&Object::Touch);

//typedef tBOOL(codex::IEventListener::*Listener)(codex::IEventData const& event);
tBOOL Object::Touch(codex::IEventData const& event )
{
	cdxTrace( "el objeto es %s", name );
	return TRUE;
}

Object::Object()
{
	name = "Objecto 1";
	m_listener = EventListenerPtr(ListenerDelegate(&Object::Touch, this));
	codex::eventManager::addListener( m_listener, "destroy_actor");
}


//typedef tBOOL(codex::IEventListener::*Listener)(codex::IEventData const& event);
void createWindow::init(void)
{
	codex::eventManager::registerEventType(codex::EventType("destroy_actor"));
	m_pObject = new Object();
	//m_listenerMemoryWarning += &createWindow::listener;
	/*
	codex::EventListenerPtr theptr = codex::EventListenerPtr(new Object());
	//EvtData_Destroy_Actor ev = EvtData_Destroy_Actor(5);


	if (codex::eventManager::addListener( theptr, codex::EventType("destroy_actor")))
	{
		cdxTrace(  ((tString)"the listener onMemory  was inserted succesfully").c_str() );
	}
	*/
	//listenersList.push_back( theptr );
} // OnInit
void createWindow::update(tFLOAT dt)
{
	//cdxTrace( (((tString)"Hola Mundo ") + dt).c_str() );
	codex::eventManager::queueEvent( codex::IEventDataPtr( new EvtData_Destroy_Actor(5) ) );
} // OnEnterFrame
void createWindow::finish(void)
{

} // OnFinish